package com.xiaoshuidi.cloud.module.bpm.controller.admin.task.vo.task;

import cn.hutool.core.date.BetweenFormatter;
import cn.hutool.core.date.DateUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Map;

@Schema(description = "管理后台 - 流程任务的 Running 进行中的分页项 Response VO")
@Data
public class BpmTaskTodoPageItemRespVO {

    /**
     * 任务编号
     */
    @Schema(description = "任务编号", required = true, example = "1024")
    private String id;

    /**
     * 任务名字
     */
    @Schema(description = "任务名字", required = true, example = "")
    private String name;

    /**
     * 接收时间
     */
    @Schema(description = "接收时间", required = true)
    private LocalDateTime claimTime;

    /**
     * 创建时间
     */
    @Schema(description = "创建时间", required = true)
    private LocalDateTime createTime;

    /**
     * 激活状态
     */
    @Schema(description = "激活状态,参见 SuspensionState 枚举", required = true, example = "1")
    private Integer suspensionState;

    /**
     * 所属流程实例
     */
    private ProcessInstance processInstance;

    /**
     * 变量
     */
    private Map<String, Object> formVariables;
    /**
     * 类型
     */
    private String type;

    public String getDuration() {
        return DateUtil.formatBetween(claimTime != null ? (Duration.between(claimTime, LocalDateTime.now())).toMillis() : (createTime != null ?
                Duration.between(createTime, LocalDateTime.now()).toMillis() : 0L), BetweenFormatter.Level.MINUTE);
    }

    @Data
    @Schema(description = "流程实例")
    public static class ProcessInstance {
        /**
         * 流程实例编号
         */
        @Schema(description = "流程实例编号", required = true, example = "1024")
        private String id;

        /**
         * 流程实例名称
         */
        @Schema(description = "流程实例名称", required = true, example = "道")
        private String name;

        /**
         * 发起人的用户编号
         */
        @Schema(description = "发起人的用户编号", required = true, example = "1024")
        private Long startUserId;

        /**
         * 发起人的用户昵称
         */
        @Schema(description = "发起人的用户昵称", required = true, example = "艿")
        private String startUserNickname;

        /**
         * 流程定义的编号
         */
        @Schema(description = "流程定义的编号", required = true, example = "2048")
        private String processDefinitionId;

        @Schema(description = "流程关联业务id")
        private String businessKey;

    }

}